<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script>
			window.onload = function()
			{
				let inputs = document.querySelectorAll('input');
				let btn = document.querySelector('button');
				let sum = 0;
				
				btn.onclick = function()
				{
					if( isNaN(parseInt(inputs[0].value)) || isNaN(parseInt(inputs[1].value)) )
					{
						alert('请输入数字');
						return;
					}
					else
					{
						sum = parseInt(inputs[0].value) + parseInt(inputs[1].value);
						alert(`相加的值为: ${sum}`);
					}
				}
			}
		</script>
	</head>
	<body>
		<input type="text" id="ip1">
		<input type="text" id="ip2">
		<button>求和</button>
	</body>
</html>